#include <iostream>
using namespace std;

 
long long rec(long long len);

 
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        long long left,right;
        cin >> left >> right;
        cout << rec(right) - rec(left-1) << endl;
    }
    return 0;
}


long long rec(long long len)
{
    if(len==0) return 0;
    long long len0{0}, ans{0}, res{0};
    while(len0 < len) 
        len0 = len0*2+1; 
    len0 = (len0-1) / 2;        
    ans = (len0+1) / 2;        
    res = len - len0 - 1;          
    return ans + 1 + res -(ans - rec(len0-res));
}